package com.example.a2205douyin.recommend;

import androidx.lifecycle.MutableLiveData;

import com.example.a2205douyin.MainActivity;
import com.example.a2205douyin.baseMVVM.viewmodel.BaseViewModel;
import com.example.a2205douyin.entity.BannerEntity;
import com.example.a2205douyin.entity.PinglunEntity;
import com.example.a2205douyin.entity.ResultEntity;
import com.example.a2205douyin.entity.VideoEntity;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RecommendViewModel extends BaseViewModel<RecommendRepo> {
    @Override
    protected RecommendRepo createRepo() {
        return new RecommendRepo();
    }
    //轮播图
    public MutableLiveData<BannerEntity> banSuccess = new MutableLiveData<>();
    public MutableLiveData<String> banFail = new MutableLiveData<>();
    public void banner(){
        repo.banner(banSuccess,banFail);
    }

    //分页查询
    public MutableLiveData<VideoEntity> videoSuccess = new MutableLiveData<>();
    public MutableLiveData<String> videoFail = new MutableLiveData<>();
    public void video(int page,int size){
        repo.video(page,size,videoSuccess,videoFail);
    }
    //搜索功能
    public MutableLiveData<VideoEntity> searchSucc = new MutableLiveData<>();
    public MutableLiveData<String> searchFail = new MutableLiveData<>();
    public void search(String keyword){
        repo.search(keyword,searchSucc,searchFail);
    }

    public MutableLiveData<ResultEntity> guanSucc = new MutableLiveData<>();
    public MutableLiveData<String> guanFail = new MutableLiveData<>();
    public void guanzhu(String authname){
        Map<String,String> map = new HashMap<>();
        map.put("authname",authname);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"),s);
        repo.guanzhu(body,guanSucc,guanFail);
    }


    public MutableLiveData<ResultEntity> loveSucc = new MutableLiveData<>();
    public MutableLiveData<String> loveFail = new MutableLiveData<>();
    public void love(int videoId){
        repo.love(videoId,loveSucc,loveFail);
    }

    public MutableLiveData<ResultEntity> noloveSucc = new MutableLiveData<>();
    public MutableLiveData<String> noloveFail = new MutableLiveData<>();

    public void nolove(int videoId){
        repo.nolove(videoId,noloveSucc,noloveFail);
    }

    public MutableLiveData<PinglunEntity> getSucc = new MutableLiveData<>();
    public MutableLiveData<String> getFail = new MutableLiveData<>();

    public void getComment(int videoId){
        repo.getComment(videoId,getSucc,getFail);
    }

    public MutableLiveData<PinglunEntity> comSucc = new MutableLiveData<>();
    public MutableLiveData<String> comFail = new MutableLiveData<>();
    public void comment(String msg,int videoId){
        Map<String,String> map = new HashMap<>();
        map.put("msg",msg);
        map.put("videoId",videoId+"");
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"),s);
        repo.comment(body,comSucc,comFail);
    }
}
